//
// Created by Administrator on 2023/11/14.
//
#include "iostream"

using namespace std;

const int N=1e5+10;
int A[N],M[N],n;

int main(){
    cin>>n;
    for (int i = 0; i < n; ++i)
        cin>>A[i];

    int res=0;
    for (int i = 0,j=0; i < n; ++i) {
        M[A[i]]++;
        while( M[A[i]]>1){
            M[A[j]]--;
            j++;
        }
        res=max(res,i-j+1);
    }
    cout<<res;

}